using System.IO;
using System.Reflection;

namespace OrbitOne.EmailProtector
{
    
    internal  class Util
    {
       

        /// <summary>
        /// Converts a string of length 4 to a 32-bit unsigned integer.
        /// </summary>
        /// <param name="Input">The string of length 4 to convert.</param>
        /// <returns>An encoded integer value representing a string of length 4.</returns>
        public static uint ConvertStringToUInt(string Input)
        {
            uint output;
            output = ((uint)Input[0]);
            output += ((uint)Input[1] << 8);
            output += ((uint)Input[2] << 16);
            output += ((uint)Input[3] << 24);
            return output;
        }

        /// <summary>
        /// Converts a 32-bit unsigned integer to a string of length 4.
        /// </summary>
        /// <param name="Input">The unsigned integer to convert to a string.</param>
        /// <returns>A string value represented by the encoded integer.</returns>
        public static string ConvertUIntToString(uint Input)
        {
            System.Text.StringBuilder output = new System.Text.StringBuilder();
            output.Append((char)((Input & 0xFF)));
            output.Append((char)((Input >> 8) & 0xFF));
            output.Append((char)((Input >> 16) & 0xFF));
            output.Append((char)((Input >> 24) & 0xFF));
            return output.ToString();
        }




        public static uint ConvertBytesToUInt(byte[] Input)
        {
            uint output;
            output = Input.Length > 0 ? ((uint)Input[0]) : 0;
            output += Input.Length > 1 ? ((uint)Input[1] << 8) : 0;
            output += Input.Length > 2 ? ((uint)Input[2] << 16) : 0;
            output += Input.Length > 3 ? ((uint)Input[3] << 24) : 0;
            return output;
        }

        public static string GetResource(string resourceName)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            TextReader textReader = new StreamReader(assembly.GetManifestResourceStream(resourceName));
            string result = textReader.ReadToEnd();
            textReader.Close();

            return result;
        }


    }

}